package controller;

import java.util.ArrayList;
import java.util.List;

import model.Billete;
import model.ItemBillete;
import beans.BilleteBean;
import beans.ItemBilleteBean;
import dao.HibernateBilleteDAO;
import dto.BilleteDTO;
import dto.ItemBilleteDTO;

public class AdministradorItemBillete {
	private static AdministradorItemBillete instancia;
	
	private AdministradorItemBillete(){
		
	}
	public static  AdministradorItemBillete getInstancia(){
		if(instancia==null)
			instancia=new AdministradorItemBillete();
		return instancia;
		
	}
	public List<ItemBilleteBean> fromModelTOBean(List<ItemBillete> efectivoTotal) {
		List<ItemBilleteBean> efectivoTotalBean=new ArrayList<ItemBilleteBean>();
		for (ItemBillete itemBillete : efectivoTotal) {
			efectivoTotalBean.add(fromModelTOBean(itemBillete));
		}		
		return efectivoTotalBean;
	}
	
	public List<ItemBilleteDTO> fromModelTODTO(List<ItemBillete> efectivoTotal) {
		List<ItemBilleteDTO> efectivoTotalDTO=new ArrayList<ItemBilleteDTO>();
		for (ItemBillete itemBillete : efectivoTotal) {
			efectivoTotalDTO.add(fromModelTODTO(itemBillete));
		}		
		return efectivoTotalDTO;
	}
	
	public ItemBilleteBean fromModelTOBean(ItemBillete itemBillete) {
		ItemBilleteBean itemBilleteBean=null;
		if(itemBillete!=null){
		itemBilleteBean=new ItemBilleteBean();
		itemBilleteBean.setIdItemBillete(itemBillete.getId());
		itemBilleteBean.setCantidad(itemBillete.getCantidad());
		itemBilleteBean.setBillete(fromModelTOBean(itemBillete.getBillete()));
		}
		return itemBilleteBean;
	}
	
	public BilleteBean fromModelTOBean(Billete billete) {
		BilleteBean billeteBean=null;
		if(billete!=null){
		billeteBean=new BilleteBean();
		billeteBean.setIdBillete(billete.getId());
		billeteBean.setDenominacion(billete.getDenominacion());
		billeteBean.setValor(billete.getValor());
		}
		return billeteBean;
	}

	public List<ItemBillete> fromDTOTOModel(List<ItemBilleteDTO> efectivoTotalDTO) {
		List<ItemBillete> efectivoTotal=new ArrayList<ItemBillete>();
		for (ItemBilleteDTO itemBilleteDTO : efectivoTotalDTO) {
			efectivoTotal.add(fromDTOTOModel(itemBilleteDTO));
		}		
		return efectivoTotal;
	}
	public ItemBillete fromDTOTOModel(ItemBilleteDTO itemBilleteDTO) {
		ItemBillete itemBillete=null;
		if(itemBilleteDTO!=null){
		itemBillete=new ItemBillete();
		itemBillete.setId(itemBilleteDTO.getId());
		itemBillete.setCantidad(itemBilleteDTO.getCantidad());
		itemBillete.setBillete(fromDTOTOModel(itemBilleteDTO.getBillete()));
		}
		return itemBillete;
	}
	
	public Billete fromDTOTOModel(BilleteDTO billeteDTO) {
		Billete billete=null;
		if(billeteDTO!=null){
		billete=new Billete();
		billete.setId(billeteDTO.getId());
		billete.setDenominacion(billeteDTO.getDenominacion());
		billete.setValor(billeteDTO.getValor());
		}
		return billete;
	}
	
	public ItemBilleteDTO fromModelTODTO(ItemBillete itemBillete) {
		ItemBilleteDTO itemBilleteDTO=null;
		if(itemBillete!=null){
			itemBilleteDTO=new ItemBilleteDTO();
			itemBilleteDTO.setId(itemBillete.getId());
			itemBilleteDTO.setCantidad(itemBillete.getCantidad());
			itemBilleteDTO.setBillete(fromModelTODTO(itemBillete.getBillete()));
		}
		return itemBilleteDTO;
	}
	
	public BilleteDTO fromModelTODTO(Billete billete) {
		BilleteDTO billeteDTO=null;
		if(billete!=null){
			billeteDTO=new BilleteDTO();
			billeteDTO.setId(billete.getId());
			billeteDTO.setDenominacion(billete.getDenominacion());
			billeteDTO.setValor(billete.getValor());
		}
		return billeteDTO;
	}
	
	public List<ItemBillete> fromBeanTOModel(List<ItemBilleteBean> efectivoTotalBean) {
		List<ItemBillete> efectivoTotal=new ArrayList<ItemBillete>();
		for (ItemBilleteBean itemBilleteBean : efectivoTotalBean) {
			efectivoTotal.add(fromBeanTOModel(itemBilleteBean));
		}		
		return efectivoTotal;
	}
	public ItemBillete fromBeanTOModel(ItemBilleteBean itemBilleteBean) {
		ItemBillete itemBillete=null;
		if(itemBilleteBean!=null){
		itemBillete=new ItemBillete();
		itemBillete.setId(itemBilleteBean.getIdItemBillete());
		itemBillete.setCantidad(itemBilleteBean.getCantidad());
		itemBillete.setBillete(fromBeanTOModel(itemBilleteBean.getBillete()));
		}
		return itemBillete;
	}
	public Billete fromBeanTOModel(BilleteBean billeteBean) {
		Billete billete=null;
		if(billeteBean!=null){
		billete=new Billete();
		billete.setId(billeteBean.getIdBillete());
		billete.setDenominacion(billeteBean.getDenominacion());
		billete.setValor(billeteBean.getValor());
		}
		return billete;
	}
	public void grabarBillete(Billete billete) {
		BilleteBean billeteb=fromModelTOBean(billete);
		HibernateBilleteDAO.getInstancia().grabarBillete(billeteb);
		
	}
	
	public Billete buscarBillete(Billete billete) {
		BilleteBean billeteb=fromModelTOBean(billete);
		billeteb=HibernateBilleteDAO.getInstancia().buscarBillete(billeteb);
		return fromBeanTOModel(billeteb);
	}
	
	public ArrayList<Billete> listBilletes() {
		ArrayList<BilleteBean> billetesBean=HibernateBilleteDAO.getInstancia().list();
		return fromBeanTOModel(billetesBean);
	}
	
	public ArrayList<Billete> fromBeanTOModel(
			ArrayList<BilleteBean> billetesBean) {
		ArrayList<Billete>billetes=new ArrayList<Billete>();
		for (BilleteBean billeteb : billetesBean) {
			Billete billete=fromBeanTOModel(billeteb);
			billetes.add(billete);
		}
		return billetes;
	}
}
